package com.comprehensive.dataservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.comprehensive.common.dto.PageResponse;
import com.comprehensive.dataservice.common.dtoConverter.PageConverter;
import com.comprehensive.dataservice.entity.FileInfo;
import com.comprehensive.dataservice.service.FileInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/file")
public class FileInfoController {

    private final FileInfoService fileInfoService;

    @Autowired
    public FileInfoController(FileInfoService fileInfoService) {
        this.fileInfoService = fileInfoService;
    }

    @PostMapping
    public boolean save(@RequestBody FileInfo fileInfo) {
        return fileInfoService.save(fileInfo);
    }

    @GetMapping("/listPage")
    public PageResponse<FileInfo> listPage(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        Page<FileInfo> page = new Page<>(pageNum, pageSize);
        IPage<FileInfo> iPage = fileInfoService.page(page, Wrappers.emptyWrapper());
        return PageConverter.convert(iPage);
    }
}